package org.dromara.hm.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.hm.domain.vo.saleOrder.HmSupplementaryPickupRecordVo;
import org.dromara.hm.domain.bo.HmSupplementaryPickupRecordBo;
import org.dromara.hm.service.IHmSupplementaryPickupRecordService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 补充提货记录
 *
 * @author Hzy
 * @date 2025-07-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/hm/supplementaryPickupRecord")
public class HmSupplementaryPickupRecordController extends BaseController {

    private final IHmSupplementaryPickupRecordService hmSupplementaryPickupRecordService;

    /**
     * 查询补充提货记录列表
     */
    @SaCheckPermission("hm:supplementaryPickupRecord:list")
    @GetMapping("/list")
    public TableDataInfo<HmSupplementaryPickupRecordVo> list(HmSupplementaryPickupRecordBo bo, PageQuery pageQuery) {
        return hmSupplementaryPickupRecordService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出补充提货记录列表
     */
    @SaCheckPermission("hm:supplementaryPickupRecord:export")
    @Log(title = "补充提货记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HmSupplementaryPickupRecordBo bo, HttpServletResponse response) {
        List<HmSupplementaryPickupRecordVo> list = hmSupplementaryPickupRecordService.queryList(bo);
        ExcelUtil.exportExcel(list, "补充提货记录", HmSupplementaryPickupRecordVo.class, response);
    }

    /**
     * 获取补充提货记录详细信息
     *
     * @param supplementaryPickupId 主键
     */
    @SaCheckPermission("hm:supplementaryPickupRecord:query")
    @GetMapping("/{supplementaryPickupId}")
    public R<HmSupplementaryPickupRecordVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long supplementaryPickupId) {
        return R.ok(hmSupplementaryPickupRecordService.queryById(supplementaryPickupId));
    }

    /**
     * 新增补充提货记录
     */
    @SaCheckPermission("hm:supplementaryPickupRecord:add")
    @Log(title = "补充提货记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HmSupplementaryPickupRecordBo bo) {
        return toAjax(hmSupplementaryPickupRecordService.insertByBo(bo));
    }

    /**
     * 修改补充提货记录
     */
    @SaCheckPermission("hm:supplementaryPickupRecord:edit")
    @Log(title = "补充提货记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HmSupplementaryPickupRecordBo bo) {
        return toAjax(hmSupplementaryPickupRecordService.updateByBo(bo));
    }

    /**
     * 删除补充提货记录
     *
     * @param supplementaryPickupIds 主键串
     */
    @SaCheckPermission("hm:supplementaryPickupRecord:remove")
    @Log(title = "补充提货记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{supplementaryPickupIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] supplementaryPickupIds) {
        return toAjax(hmSupplementaryPickupRecordService.deleteWithValidByIds(List.of(supplementaryPickupIds), true));
    }
}
